﻿var typeid = sessionStorage.getItem("id")
var name = sessionStorage.getItem("name")
let Tnumber = document.querySelector("#Tnumber");
if (typeid == null) {
    location.href = "/Table/TableTypeInfo"
}
document.getElementById("tname").innerHTML = `<span style='color:var(--ZhuTiSe)'>${name}</span>详情`;

let Status = [{
    status: -1,
    name: '全部'
}, {
    status: 0,
    name: '空闲'
}, {
    status: 1,
    name: '占用'
}, {
    status: 2,
    name: '不可用'
}]

let where = {
    number: '',
    type: typeid,
    status: -1
};

var loadTalbe;


function BindTable(obj) {
    layui.use('table', function () {
        var table = layui.table;

        table.render({
            elem: '#table'
            , data: obj
            /* , cellMinWidth: 80*/ //全局定义常规单元格的最小宽度，layui 2.2.1 新增
            , cols: [[

                { field: 'number', title: '桌子号码' },
                { field: 'sumber', title: '总人数' },
                { field: 'typename', title: '桌子类型' },
                { field: 'status', title: '桌子状态', templet: '#status' },
                { field: 'occupy', title: '占用人数' },
                { title: '操作', toolbar: "#barDemo" }
            ]]
        });
        Peng.closeload(loadTalbe);

        table.on('tool(table)', function (obj) { //注：tool 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
            var data = obj.data; //获得当前行数据
            var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
            switch (layEvent) {

                case "detail":
                    console.log(data.id)
                    break;
                case "edit":
                    sessionStorage.setItem("tid", data.id);
                    sessionStorage.setItem("typeid", data.type);
                    sessionStorage.setItem("status", data.status);
                    sessionStorage.setItem("number", data.number);
                    sessionStorage.setItem("sumber", data.sumber);
                    sessionStorage.setItem("occupy", data.occupy);
                    location.href = "/Table/EditTableHtml";
                    break;
            }
        })
    });

}




function GetTableType() {


    loadTalbe = Peng.load({ box: 'Cols', style: 'circle', color: 'ZhutiSe', content: '加载桌子类型数据中.....' });

    $.get("/Table/getTable", { number: where.number, type: where.type, status: where.status }).then(res => {
        BindTable(res.data);
    });
}

/*GetTableType();*/

var query = function () {

    where.number = Tnumber.value;
    GetTableType();
    where.number = "";
    Tnumber.value = "";
}


Peng_Select.CreateElement("StatusSelect", Status, 'name', (res) => {
    where.status = res.status;
    where.number = Tnumber.value;
    GetTableType()
    where.number = "";
    Tnumber.value = "";
});


